<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/jsp/common.jsp"%>

<script type="text/javascript">
	var $mainModal = $("#main-loading");
	var usercont = {
		currentPage : 1,
		ajaxList : function(pageNum) {
			$mainModal.modal();
			$("#headBtnGroup").show();
			usercont.currentPage = pageNum;

			searchForm.pageNum.value = pageNum;
			
			$.ajax({
				url : '${basePath}/manage/searchUser',
				method : 'POST',
				data : $("#searchForm").serialize(),
				dataType : 'html',
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);			
				},
				error : function(data) {
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {
						icon : 2
					});
				}
			});

		},
		showSearchBox : function() {
			if ($("#hideBar").css("display") == "none") {
				$("#hideBar").slideDown();
			} else {
				$("#hideBar").slideUp();
			}
		},
		search : function() {
			$mainModal.modal();
			searchForm.pageNum.value = 1;
			$.ajax({
				url : "${basePath}/manage/searchUser",
				method : 'POST',
				data : $("#searchForm").serialize(),
				dataType : 'html',
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);
					
				},
				error : function(data) {
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {
						icon : 2
					});
				}
			});
		},
		reset : function() {
			$("#searchForm")[0].reset();
		},
		deleteUser : function(userId, userName) {
			layer.confirm('确定删除  ' + userName + ' 这个用户？', {
				btn : [ '确定', '取消' ],
				icon : 3
			}, function() {
				$mainModal.modal();
				$.ajax({
					url : "${basePath}/manage/userDel",
					method : 'POST',
					data : {
						"userId" : userId
					},
					dataType : 'html',
					success : function(data) {
						$mainModal.modal("close");
						if (data == "true" || data == true) {
							layer.msg('用户删除成功', {
								icon : 1
							});
							usercont.ajaxList(usercont.currentPage);
						} else {
							layer.msg('用户删除失败', {
								icon : 2
							});
						}
					},
					error : function(data) {
						$mainModal.modal("close");
						layer.msg("连接服务器时遇到错误！", {
							icon : 2
						});
					}
				});
			}, function() {});
		}
	};

	/** 
	 * 建立一个_this对象 
	 * 将查询列表的ajaxList方法赋值给$.ajaxList
	 * 公用分页插件将会使用这个方法分页
	 */
	var _this = {
		_ajaxList : usercont.ajaxList
	}

	$(document).ready(function() {
		usercont.ajaxList(1);
	});
</script>

<div class="admin-content-body">
	<div class="am-cf am-padding am-padding-bottom-0">
		<div class="am-fl am-cf">
			<strong class="am-text-primary am-text-lg">用户</strong> / <small>USER</small>
		</div>
	</div>
	<hr>
	<div class="main">
		<div class="am-g">
			<div class="am-u-sm-12" id="headBtnGroup">
				<!--<button type="button" class="am-btn am-btn-default am-btn-xs am-fl"
					onclick="usercont.edit()">
					<span class="am-icon-plus"></span> 新增
				</button> -->

				<div class="am-fl" id="file-list"
					style="margin-top: 6px; margin-left: 10px"></div>
				<button type="button" class="am-btn am-btn-default am-btn-xs am-fr"
					onclick="usercont.showSearchBox()">
					<span class="am-icon-search"></span> 搜索
				</button>
			</div>
		</div>
		<div class="am-g" style="margin-top: 10px;">
			<div id="hideBar" style="display: none;">
				<%@ include file="searchUser.jsp"%>
			</div>
			<div class="am-u-sm-12 am-u-md-12" id="tableBody"></div>
		</div>
	</div>
</div>
<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1"
	id="main-loading">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">正在载入...</div>
		<div class="am-modal-bd">
			<span class="am-icon-spinner am-icon-spin"></span>
		</div>
	</div>
</div>